package pers.qianyu.month_202012.date_20201219.bit_operation;

/**
 * 191. 位1的个数
 * https://leetcode-cn.com/problems/number-of-1-bits/
 *
 * @author mizzle rain
 * @date 2020-12-19 21:16
 */
public class HammingWeight {
    public int hammingWeight(int n) {
        int res = 0;
        while (n != 0) {
            n = n & (n - 1);
            res++;
        }
        return res;
    }
}
